import "./public-path";
import { createApp } from "vue";
import App from "./App.vue";
import router from "./router";
import store, { setupStore } from "./store";
import "./icon";
import { registerApp } from "./register";
import SharedModule from "./shared";
import less from "less";
//全局初始化样式
import "normalize.css";
import "@/assets/css/base.less";
let instance: any = null;
function render(props: any = {}) {
  (window as any).G = props;
  const { container } = props;
  // 当传入的 shared 为空时，使用子应用自身的 shared
  // 当传入的 shared 不为空时，主应用传入的 shared 将会重载子应用的 shared
  // 建议：只在存在复杂状态且需要子应用自行维护状态池才使用shared
  const { shared = SharedModule.getShared() } = props;
  SharedModule.overloadShared(shared);
  //需要在store中拿到props
  setupStore();
  instance = createApp(App);
  instance
    .use(store)
    .use(router)
    .use(registerApp)
    .use(less)
    .mount(container ? container.querySelector("#app") : "#app");
}
// 如果是单独启动的子文件，保证仍能正常运行
if (!(window as any).__POWERED_BY_QIANKUN__) {
  render();
}
export async function bootstrap() {
  console.log("[vue] vue app bootstraped");
}
export async function mount(props: any) {
  render(props);
}
export async function unmount() {
  instance.unmount();
  instance._container.innerHTML = "";
  instance = null;
}
